# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
# Contributor: Jingbei Li <i@jingbei.li>

pkgname=intel-oneapi-dpcpp-debugger
_pkgver=2023.2.0
_debpkgrel=49330
pkgver=${_pkgver}_${_debpkgrel}
pkgrel=1
pkgdesc='Intel OneAPI GDB'
arch=('loong64' 'x86_64')
url='https://software.intel.com/content/www/us/en/develop/tools/oneapi.html'
license=("custom")
# Eclipse files are still at previous version
_eclipse_pkgver=2023.1.0
_eclipse_debpkgrel=43513
source=("https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-${_pkgver}-${_pkgver}-${_debpkgrel}_amd64.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-eclipse-cfg-${_eclipse_pkgver}-${_eclipse_debpkgrel}_all.deb")
b2sums=('e5a928301cceb1934b7d70c7590b68a3d3c7f50a5c5f7b1cf197233b97ce78bc54406ffda604d355c94d995d5e886b6de787b6e424a08673f76e6258ec3a83f9'
        'db56931bc8c565b573d2623b3564bfb6b92d58baf199ab8e816c929db6be1b936fcdd04dc2b74fb28624aa93c83b0be388474f5395244dfc162ff39da14d0cd8')
noextract=(
	"${pkgname}-${_pkgver}-${_pkgver}-${_debpkgrel}_amd64.deb"
	"${pkgname}-eclipse-cfg-${_eclipse_pkgver}-${_eclipse_debpkgrel}_all.deb"
)
depends=('intel-oneapi-common')
provides=("$pkgname-eclipse-cfg")
conflicts=('intel-oneapi-basekit')

package() {
    cd "${srcdir}"
    ar x "${srcdir}/${pkgname}-${_pkgver}-${_pkgver}-${_debpkgrel}_amd64.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    ar x "${srcdir}/${pkgname}-eclipse-cfg-${_eclipse_pkgver}-${_eclipse_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${pkgdir}"
    rm data.tar.xz

    local _deb_path='/opt/intel/oneapi/debugger/'
    ln -s "${_deb_path}/${_pkgver}" "${pkgdir}/${_deb_path}/latest"
    # Allow libs to be found
    local _lib_path='/opt/intel/oneapi/debugger'
    local _ldso_conf="${pkgdir}"/etc/ld.so.conf.d
    install -d "${_ldso_conf}"
    echo "${_lib_path}/latest/gdb/intel64/lib" > "${_ldso_conf}/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
}
